package com.league.zjxn.main.adapter

import android.widget.ImageView
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.league.zjxn.R
import com.league.zjxn.entity.ProjectData
import com.league.zjxn.entity.Projects
import com.league.zjxn.main.home.ProjectDetailsActivity
import com.module.lemlin.image.loadCenterImage

class ProjectGroupAdapter :
    BaseQuickAdapter<Projects, BaseViewHolder>(R.layout.item_project_group) {
    override fun convert(holder: BaseViewHolder, item: Projects) {
        holder.getView<ImageView>(R.id.ivProjectGroupTitle).apply {
            setImageResource(if (item.id == 2) R.mipmap.ic_30002 else if (item.id == 3) R.mipmap.ic_30003 else R.mipmap.ic_30004)
        }
        holder.getView<RecyclerView>(R.id.rvProjectGroupBody).apply {
            layoutManager = GridLayoutManager(context,3)
        }
            .adapter = ProjectChildAdapter().apply {
            setNewInstance(item.data)
            setOnItemClickListener { _, _, position ->
                val itemData = getItem(position)
                ProjectDetailsActivity.openProject(item.name,itemData)
            }
        }
    }
}

class ProjectChildAdapter :
    BaseQuickAdapter<ProjectData, BaseViewHolder>(R.layout.item_project_child) {
    override fun convert(holder: BaseViewHolder, item: ProjectData) {
        holder.setText(R.id.tvProjectChildName, item.title)
            .getView<ImageView>(R.id.ivProjectChildImage)
            .loadCenterImage(item.cover)
    }
}